/*****************************************************************************/
/**
 *  @file   ResourceMonitor.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id: ResourceMonitor.cpp 81 2013-12-13 02:46:41Z naohisa.sakamoto $
 */
/*****************************************************************************/
#include "ResourceMonitor.h"
#include <kvs/SystemInformation>
#include <kvs/cuda/Device>


ResourceMonitor::ResourceMonitor( const size_t device_id )
{
    if ( kvs::cuda::Device::IsEnabled() )
    {
        m_device = kvs::SharedPointer<kvs::cuda::Device>( new kvs::cuda::Device( device_id ) );
    }
}

void ResourceMonitor::update()
{
    if ( m_device ) m_device->update();
}

size_t ResourceMonitor::numberOfCPUs() const
{
    return kvs::SystemInformation::NumberOfProcessors();
}

size_t ResourceMonitor::numberOfGPUs() const
{
    return m_device ? kvs::cuda::Device::Count() : 0;
}

size_t ResourceMonitor::totalCPUMemory() const
{
    return kvs::SystemInformation::TotalMemorySize();
}

size_t ResourceMonitor::freeCPUMemory() const
{
    return kvs::SystemInformation::FreeMemorySize();
}

size_t ResourceMonitor::totalGPUMemory() const
{
    return m_device ? m_device->totalMemory() : 0;
}

size_t ResourceMonitor::freeGPUMemory() const
{
    return m_device ? m_device->freeMemory() : 0;
}
